package com.example.reagent_management.ui.home.pojo;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.UUID;

/**
 * 首页位置信息
 * UUID 为架子唯一标识符
 *
 * 位置和试剂总数可能会随时发生改变
 */
public class PositionCounts implements Parcelable  {

    public PositionCounts() {
        UUID = java.util.UUID.randomUUID().toString().replace("-","");
    }

    public PositionCounts(Integer position, Integer counts) {
        this.position = position;
        this.counts = counts;
        this.UUID = java.util.UUID.randomUUID().toString().replace("-","");
    }

    private Integer position;
    private Integer counts;
    private final String UUID;


    protected PositionCounts(Parcel in) {
        if (in.readByte() == 0) {
            position = null;
        } else {
            position = in.readInt();
        }
        if (in.readByte() == 0) {
            counts = null;
        } else {
            counts = in.readInt();
        }
        UUID = in.readString();
    }

    public static final Creator<PositionCounts> CREATOR = new Creator<PositionCounts>() {
        @Override
        public PositionCounts createFromParcel(Parcel in) {
            return new PositionCounts(in);
        }

        @Override
        public PositionCounts[] newArray(int size) {
            return new PositionCounts[size];
        }
    };

    public String getUUID() {
        return UUID;
    }

    public Integer getPosition() {
        return position;
    }

    public void setPosition(Integer position) {
        this.position = position;
    }

    public Integer getCounts() {
        return counts;
    }

    public void setCounts(Integer counts) {
        this.counts = counts;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (position == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(position);
        }
        if (counts == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(counts);
        }
        dest.writeString(UUID);
    }
}
